#ifndef __SHADER_PROGRAM_GLES_H__
#define __SHADER_PROGRAM_GLES_H__

#pragma once

#include "RendererGLESCompileConfig.h"
#include "ShaderProgram.h"

namespace Nezha
{

	class RendererGLES;

	///** Vertex attribute binding to predefined name array. */
	//struct NEZHA_GLES_ENTRY PredVertexAttrib
	//{
	//	VertexSementic mSementic;
	//	int mIndex;
	//	int mExtendIndex;

	//	PredVertexAttrib()
	//		:mSementic(VS_NONE)
	//		,mIndex(0)
	//		,mExtendIndex(0)
	//	{
	//	}
	//};

	//typedef PArray<PredVertexAttrib> PredVertexAttribArray;

	typedef PArray<VertexElement> VertexElementArray;

	/** Shader program implement of opengl es2, include vertex shader, pixel shader, 
	and link program. */
	class ProgramGLES : public ShaderProgram
	{
	public:
		ProgramGLES(RendererGLES* r);
		~ProgramGLES();

		GLuint getVertexShaderHandle();
		GLuint getPixelShaderHandle();
		GLuint getProgramHandle();

		virtual bool loadFromSource(const _string& source, ShaderProgram::Shader shd);

		virtual bool loadFromBinary(SystemMemBufferPtr bin);

		bool link();

		bool bindToCurrent();

		GLint getAttribLocation(VertexSementic vs);

		/** retrieve predefined vertex attrib names. */
		static const char* GetPredVertexAttrName(VertexSementic vs);

		static VertexSementic GetPredVertexAttrSem(const char* varName, int& subIndex);

NEZHA_INTERNAL:

		//// for shader manager parsing.
		//PredVertexAttribArray& _internalAccessPredVA();

		VertexElementArray& _internalAccessPredVEA();

	private:
		void retrievePredVertexAttribs();

	private:
		GLuint mVSHandle;
		GLuint mPSHandle;
		GLuint mProgramHandle;
		GLuint mGLStatus;

		RendererGLES* mRenderer;

		static const char* msPredVertexAttribName[VS_MAX_SEMENTICS];

		//PredVertexAttribArray mPredVertexAttribs;

		// all the active attributes.
		VertexElementArray mPredVertexElements;
	};

	inline GLuint ProgramGLES::getVertexShaderHandle()
	{
		return mVSHandle;
	}

	inline GLuint ProgramGLES::getPixelShaderHandle()
	{
		return mPSHandle;
	}

	inline GLuint ProgramGLES::getProgramHandle()
	{
		return mProgramHandle;
	}

	//inline PredVertexAttribArray& ProgramGLES::_internalAccessPredVA()
	//{
	//	return mPredVertexAttribs;
	//}

	inline VertexElementArray& ProgramGLES::_internalAccessPredVEA()
	{
		return mPredVertexElements;
	}

}//end Nezha

#endif //end __SHADER_PROGRAM_GLES_H__